﻿@model AllUserSettingsModel

@using Giant.Core.Domain.Users;
@using Giant.Services

@{
    //page title
    ViewBag.Title = T("Admin.Configuration.Settings.AllUser").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("User and user settings");
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="content-header clearfix">
        <h1 class="pull-left">
            @T("Admin.Configuration.Settings.AllUser")
        </h1>
        <div class="pull-right">
            <button type="submit" name="save" class="btn bg-blue">
                <i class="fa fa-floppy-o"></i>
                @T("Admin.Common.Save")
            </button>
        </div>
    </div>
    @Html.ValidationSummary(false)

    <script>
        $(document).ready(function() {
            bindBootstrapTabSelectEvent('usersettings-edit');
        });
    </script>

    <div class="content">
        <div class="form-horizontal">
            @Html.Action("Mode", "Setting")

            <div id="usersettings-edit" class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                    @Html.RenderBootstrapTabHeader("tab-user", @T("Admin.Configuration.Settings.AllUser.UserSettings"), true)
                    @Html.RenderBootstrapTabHeader("tab-userformfields", @T("Admin.Configuration.Settings.AllUser.UserFormFields"))
                </ul>
                <div class="tab-content">
                    @Html.RenderBootstrapTabContent("tab-user", @TabUserSettings(), true)
                    @Html.RenderBootstrapTabContent("tab-userformfields", @TabUserFormFields())
                </div>
            </div>
        </div>
    </div>

    {
        //custom tabs
        var eventMessage = new AdminTabStripCreated(this.Html, "usersettings-edit");
        EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
        foreach (var eventBlock in eventMessage.BlocksToRender)
        {
            @eventBlock
        }
    }

    @*save selected tab name*@
	<input type="hidden" id="selected-tab-name" name="selected-tab-name" value="@(Html.GetSelectedTabName())">
}

@helper TabUserSettings()
{

    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.UserRegistrationType)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtDropDownListFor(model => model.UserSettings.UserRegistrationType, ((UserRegistrationType) Model.UserSettings.UserRegistrationType).ToSelectList())
                        @Html.ValidationMessageFor(model => model.UserSettings.UserRegistrationType)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.NotifyNewUserRegistration)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.NotifyNewUserRegistration)
                        @Html.ValidationMessageFor(model => model.UserSettings.NotifyNewUserRegistration)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.UsernamesEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.UsernamesEnabled)
                        @Html.ValidationMessageFor(model => model.UserSettings.UsernamesEnabled)
                    </div>
                </div>
                <div class="form-group advanced-setting" id="pnlAllowUsersToChangeUsernames">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.AllowUsersToChangeUsernames)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.AllowUsersToChangeUsernames)
                        @Html.ValidationMessageFor(model => model.UserSettings.AllowUsersToChangeUsernames)
                    </div>
                </div>
                <div class="form-group advanced-setting" id="pnlCheckUsernameAvailability">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.CheckUsernameAvailabilityEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.CheckUsernameAvailabilityEnabled)
                        @Html.ValidationMessageFor(model => model.UserSettings.CheckUsernameAvailabilityEnabled)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.AllowViewingProfiles)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.AllowViewingProfiles)
                        @Html.ValidationMessageFor(model => model.UserSettings.AllowViewingProfiles)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.AllowUsersToUploadAvatars)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.AllowUsersToUploadAvatars)
                        @Html.ValidationMessageFor(model => model.UserSettings.AllowUsersToUploadAvatars)
                    </div>
                </div>
                <div class="form-group advanced-setting" id="pnlDefaultAvatarEnabled">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.DefaultAvatarEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.DefaultAvatarEnabled)
                        @Html.ValidationMessageFor(model => model.UserSettings.DefaultAvatarEnabled)
                    </div>
                </div>                
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.ShowUsersJoinDate)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.ShowUsersJoinDate)
                        @Html.ValidationMessageFor(model => model.UserSettings.ShowUsersJoinDate)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.UserNameFormat)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtDropDownListFor(model => model.UserSettings.UserNameFormat, ((UserNameFormat) Model.UserSettings.UserNameFormat).ToSelectList())
                        @Html.ValidationMessageFor(model => model.UserSettings.UserNameFormat)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.PasswordMinLength)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.PasswordMinLength)
                        @Html.ValidationMessageFor(model => model.UserSettings.PasswordMinLength)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.DefaultPasswordFormat)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtDropDownListFor(model => model.UserSettings.DefaultPasswordFormat, ((PasswordFormat) Model.UserSettings.DefaultPasswordFormat).ToSelectList())
                        @Html.ValidationMessageFor(model => model.UserSettings.DefaultPasswordFormat)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.PasswordRecoveryLinkDaysValid)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.PasswordRecoveryLinkDaysValid)
                        @Html.ValidationMessageFor(model => model.UserSettings.PasswordRecoveryLinkDaysValid)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.EnteringEmailTwice)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.EnteringEmailTwice)
                        @Html.ValidationMessageFor(model => model.UserSettings.EnteringEmailTwice)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.HideNewsletterBlock)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.HideNewsletterBlock)
                        @Html.ValidationMessageFor(model => model.UserSettings.HideNewsletterBlock)
                    </div>
                </div>
                <div class="form-group advanced-setting" id="pnlNewsletterBlockAllowToUnsubscribe">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.NewsletterBlockAllowToUnsubscribe)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.NewsletterBlockAllowToUnsubscribe)
                        @Html.ValidationMessageFor(model => model.UserSettings.NewsletterBlockAllowToUnsubscribe)
                    </div>
                </div>
                <div class="form-group advanced-setting">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.SiteLastVisitedPage)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.SiteLastVisitedPage)
                        @Html.ValidationMessageFor(model => model.UserSettings.SiteLastVisitedPage)
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $(document).ready(function() {
                    $("#@Html.FieldIdFor(model => model.UserSettings.AllowUsersToUploadAvatars)").click(toggleAvatar);
                    $("#@Html.FieldIdFor(model => model.UserSettings.UsernamesEnabled)").click(toggleUsername);

                    toggleAvatar();
                    toggleUsername();
                });

                function toggleAvatar() {
                    if ($('#@Html.FieldIdFor(model => model.UserSettings.AllowUsersToUploadAvatars)').is(':checked')) {
                        $('#pnlDefaultAvatarEnabled').show();
                    } else {
                        $('#pnlDefaultAvatarEnabled').hide();
                    }
                }

                function toggleUsername() {
                    if ($('#@Html.FieldIdFor(model => model.UserSettings.UsernamesEnabled)').is(':checked')) {
                        $('#pnlAllowUsersToChangeUsernames').show();
                        $('#pnlCheckUsernameAvailability').show();
                    } else {
                        $('#pnlAllowUsersToChangeUsernames').hide();
                        $('#pnlCheckUsernameAvailability').hide();
                    }
                }
            </script>
        </div>
        <div class="panel panel-default advanced-setting">
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.DateTimeSettings.AllowUsersToSetTimeZone)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.DateTimeSettings.AllowUsersToSetTimeZone)
                        @Html.ValidationMessageFor(model => model.DateTimeSettings.AllowUsersToSetTimeZone)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.DateTimeSettings.DefaultSiteTimeZoneId)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtDropDownListFor(model => model.DateTimeSettings.DefaultSiteTimeZoneId, Model.DateTimeSettings.AvailableTimeZones)
                        @Html.ValidationMessageFor(model => model.DateTimeSettings.DefaultSiteTimeZoneId)
                    </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default advanced-setting">
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.ExternalAuthenticationSettings.AutoRegisterEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.ExternalAuthenticationSettings.AutoRegisterEnabled)
                        @Html.ValidationMessageFor(model => model.ExternalAuthenticationSettings.AutoRegisterEnabled)
                    </div>
                </div>
            </div>
        </div>
    </div>
}

@helper TabUserFormFields()
{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#@Html.FieldIdFor(model => model.UserSettings.DateOfBirthEnabled)").click(toggleUserRequiredFormField);
            $("#@Html.FieldIdFor(model => model.UserSettings.DateOfBirthRequired)").click(toggleUserRequiredFormField);
            $("#@Html.FieldIdFor(model => model.UserSettings.PhoneEnabled)").click(toggleUserRequiredFormField);
            $("#@Html.FieldIdFor(model => model.UserSettings.NewsletterEnabled)").click(toggleNewsletterEnabledField);
            $("#@Html.FieldIdFor(model => model.UserSettings.HideNewsletterBlock)").click(toggleHideNewsletterBlock);
            
            toggleUserCountryFormField();
            toggleUserStateProvinceFormField();
            toggleUserRequiredFormField();
            toggleNewsletterEnabledField();
            toggleHideNewsletterBlock();
        });
        
        function toggleUserRequiredFormField() {
            if ($('#@Html.FieldIdFor(model => model.UserSettings.DateOfBirthEnabled)').is(':checked')) {
                $('#pnlUserDateOfBirthRequired').show();
            } else {
                $('#pnlUserDateOfBirthRequired').hide();
            }

            if ($('#@Html.FieldIdFor(model => model.UserSettings.DateOfBirthEnabled)').is(':checked') &&
                $('#@Html.FieldIdFor(model => model.UserSettings.DateOfBirthRequired)').is(':checked')) {
                $('#pnlDateOfBirthMinimumAge').show();
            } else {
                $('#pnlDateOfBirthMinimumAge').hide();
            }

            if ($('#@Html.FieldIdFor(model => model.UserSettings.PhoneEnabled)').is(':checked')) {
                $('#pnlUserPhoneRequired').show();
            } else {
                $('#pnlUserPhoneRequired').hide();
            }

        }

        function toggleNewsletterEnabledField() {
            if ($('#@Html.FieldIdFor(model => model.UserSettings.NewsletterEnabled)').is(':checked')) {
                $('#pnlUserNewsletterTickedByDefault').show();
            } else {
                $('#pnlUserNewsletterTickedByDefault').hide();
            }
        }

        function toggleHideNewsletterBlock() {
            if ($('#@Html.FieldIdFor(model => model.UserSettings.HideNewsletterBlock)').is(':checked')) {
                $('#pnlNewsletterBlockAllowToUnsubscribe').hide();
            }
            else {
                $('#pnlNewsletterBlockAllowToUnsubscribe').show();
            }
        }
    </script>

    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                <p>
                    <em>@T("Admin.Configuration.Settings.AllUser.UserFormFields.Description")</em>
                </p>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.GenderEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.GenderEnabled)
                        @Html.ValidationMessageFor(model => model.UserSettings.GenderEnabled)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.DateOfBirthEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.DateOfBirthEnabled)
                        @Html.ValidationMessageFor(model => model.UserSettings.DateOfBirthEnabled)
                    </div>
                </div>
                <div class="form-group" id="pnlUserDateOfBirthRequired">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.DateOfBirthRequired)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.DateOfBirthRequired)
                        @Html.ValidationMessageFor(model => model.UserSettings.DateOfBirthRequired)
                    </div>
                </div>
                <div class="form-group" id="pnlDateOfBirthMinimumAge">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.DateOfBirthMinimumAge)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.DateOfBirthMinimumAge)
                        @Html.ValidationMessageFor(model => model.UserSettings.DateOfBirthMinimumAge)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.PhoneEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.PhoneEnabled)
                        @Html.ValidationMessageFor(model => model.UserSettings.PhoneEnabled)
                    </div>
                </div>
                <div class="form-group" id="pnlUserPhoneRequired">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.PhoneRequired)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.PhoneRequired)
                        @Html.ValidationMessageFor(model => model.UserSettings.PhoneRequired)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.AcceptPrivacyPolicyEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.AcceptPrivacyPolicyEnabled)
                        @Html.ValidationMessageFor(model => model.UserSettings.AcceptPrivacyPolicyEnabled)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.NewsletterEnabled)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.NewsletterEnabled)
                        @Html.ValidationMessageFor(model => model.UserSettings.NewsletterEnabled)
                    </div>
                </div>
                <div class="form-group" id="pnlUserNewsletterTickedByDefault">
                    <div class="col-md-3">
                        @Html.ExtLabelFor(model => model.UserSettings.NewsletterTickedByDefault)
                    </div>
                    <div class="col-md-9">
                        @Html.ExtEditorFor(model => model.UserSettings.NewsletterTickedByDefault)
                        @Html.ValidationMessageFor(model => model.UserSettings.NewsletterTickedByDefault)
                    </div>
                </div>
            </div>
        </div>
        @*render custom user attributes*@
        @Html.Action("ListBlock", "UserAttribute")      
    </div>
}

